package org.exteen.exec;

import org.exteen.ExteenException;
import org.exteen.parser.Node;

public class DynamicContext extends ExteenContext {

    private final Node callerBody;

    public DynamicContext(ExteenContext parent, Node root) {
        super(parent, root);
        this.callerBody = parent.getNode();
    }

    public Node getCallerBody(String bodyTagName) {
        if (bodyTagName==null) {
            return callerBody;
        }
        for (Object o: callerBody.getChildren()) {
            if (o instanceof Node) {
                Node c = (Node) o;
                if (bodyTagName.equals(c.getTag()) && callerBody.getNamespace().equals(c.getNamespace())) {
                    return c;
                }
            }
        }
        throw new ExteenException("Subtag " + bodyTagName + " not found in the body");
    }

    public boolean isDerivingVariables() {
        return false;
    }
}